package org.tp.edifact.syntax;

import static org.junit.Assert.*;

import org.junit.Test;

public class TestACharacterSet {
   
   private static final char[][] INVALID_CHARACTER_SETS = 
      {
         {},                                          //| Empty
         {':'},                                       //| One element.
         {':', '+'},                                  //| Two elements.
         {':', '+', '.'},                             //| Three elements.
         {':', '+', '.', '?'},                        //| Four elements.
         {':', '+', '.', '?', ' '},                   //| Five elements.
         {':', '+', '.', '?', ' ', '\'', '*'},        //| Seven elements.
         {':', '+', '.', '?', ' ', '\'', '*', '%'},   //| Eight elements.
         {':', '+', '.', '?', ' ', ':'},              //| First and last duplicated.
         {':', '+', '.', '?', '+', '\''},             //| 2 & 5 duplicated.
         {':', '+', '.', '.', ' ', '\''}              //| 3 & 4 duplicted.
      };

   @Test
   public void testValidateCharacterSet() {
      for (int i = 0; i < INVALID_CHARACTER_SETS.length; i++) {
         assertFalse(
               "Character set "
                  + i
                  + ": "
                  + new String(INVALID_CHARACTER_SETS[i])
                  + " shall not be valid.",
               ACharacterSet.validateServiceCharacterSet(INVALID_CHARACTER_SETS[i]));
      }      
   }

   @Test
   public void testValidateCharacterSet2() {
      String[] invalid = new String[INVALID_CHARACTER_SETS.length];
      
      for (int i = 0; i < invalid.length; i++) {
         invalid[i] = new String(INVALID_CHARACTER_SETS[i]);
      }
            
      for (int i = 0; i < invalid.length; i++) {
         assertFalse(
               "Character set "
                  + i
                  + ": \""
                  + invalid[i]
                  + "\" shall not be valid.",
               ACharacterSet.validateServiceCharacterSet(invalid[i]));
      }      
   }
}
